import { useIntersectionObserver } from "@vueuse/core";
import { ref } from "vue";

// 封装数据懒加载函数
export function useLazyData(callback: () => void) {
  const target = ref(null);

  const { stop } = useIntersectionObserver(target, ([{ isIntersecting }]) => {
    if (isIntersecting) {
      callback();
      stop();
    }
  });

  return target;
}
